home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr10 / swagg_m.zip / MOUSE.SWG < prev   
Text File  |  1993-06-11  |  49KB  |  1 lines

  1. SWAGOLX.EXE (c) 1993 GDSOFT  ALL RIGHTS RESERVED 00004         RODENT MANAGMENT ROUTINES                                         1      05-28-9313:52ALL                      SWAG SUPPORT TEAM        MOUSLIB.PAS              IMPORT              293         {π***************************************************************************π*                                  MouseLib                               *    *π* Release 6.0 - Added demo Program - Please refer to MOUSETST.PAS to      *π* see a demo of the mouseLib Unit usage.                                  *π***************************************************************************π}ππUnit Mouse;ππInterfaceππUsesπ  Dos;ππConstπ    MOUSEinT = $33; {mouse driver interrupt}π  LEFTBUTtoN = 1; {bit 0}π  RIGHTBUTtoN = 2; {bit 1}π  MIDDLEBUTtoN = 4; {bit 2}ππ  CURSor_LOCATION_CHANGED = 1; {event mask bits}π  LEFT_BUTtoN_PRESSED = 2;π  LEFT_BUTtoN_RELEASED = 4;π  RIGHT_BUTtoN_PRESSED = 8;π  RIGHT_BUTtoN_RELEASED = 16;π  MIDDLE_BUTtoN_PRESSED = 32;π  MIDDLE_BUTtoN_RELEASED = 64;ππTypeπ    mouseType = (twoButton,threeButton,another);π  buttonState = (buttonDown,buttonUp);π  direction = (moveRight,moveLeft,moveUp,moveDown,noMove);π  grCursorType = Recordπ      xH,yH : Byte; {x,y Hot Point}π    data  : Pointer;  {cursor look Pointer}π  end;ππVarπ    mouse_present : Boolean;π  mouse_buttons : mouseType;π  eventX,eventY,eventButtons : Word; {any event handler should update}π  eventhappened : Boolean;           {these Vars to use getLastEvent }π  XMotions,YMotions : Word;          {per 8 pixels}π  mouseCursorLevel : Integer;ππ  {if > 0 mouse cursor is visiable, otherwise not, containes the levelπ   of showMouseCursor/hideMouseCursor}ππConstπ    LastMask : Word = 0;π  lastHandler : Pointer = Nil;ππ  {when changing the interrupt handler temporarily, save BEForE theπ   change these to Variables, and restore them when neccessary}ππ  lastCursor : grCursorType = (π                              xH : 0;π                            yH : 0;π                          data : nil );ππ  {when changing Graphic cursor temporarily, save these values BEForEπ      the change, and restore when neccessary}ππConstπ    click_Repeat  = 10; { Recommended value For waitForRelease timeOut }ππProcedure initMouse; {when replacing mouse mode do that..!}πProcedure showMouseCursor;πProcedure hideMouseCursor;πFunction  getMouseX : Word;πFunction  getMouseY : Word;πFunction  getButton(Button : Byte) : buttonState;πFunction  buttonPressed : Boolean;πProcedure setMouseCursor(x,y : Word);πFunction  LastXPress(Button : Byte) : Word;πFunction  LastYPress(Button : Byte) : Word;πFunction  ButtonPresses(Button : Byte) : Word; {from last last check}πFunction  LastXRelease(Button : Byte) : Word;πFunction  LastYRelease(Button : Byte) : Word;πFunction  ButtonReleases(Button : Byte) : Word; {from last last check}πProcedure mouseBox(left,top,right,bottom : Word); {limit mouse rectangle}πProcedure GraphicMouseCursor(xHotPoint,yHotPoint : Byte; dataofs : Pointer);πProcedure HardwareTextCursor(fromLine,toLine : Byte);πProcedure softwareTextCursor(screenMask,cursorMask : Word);πFunction  recentXmovement : direction;πFunction  recentYmovement : direction;πProcedure setArrowCursor;πProcedure setWatchCursor;πProcedure setUpArrowCursor;πProcedure setLeftArrowCursor;πProcedure setCheckMarkCursor;πProcedure setPointingHandCursor;πProcedure setDiagonalCrossCursor;πProcedure setRectangularCrossCursor;πProcedure setHourGlassCursor;πProcedure setNewWatchCursor;πProcedure setEventHandler(mask : Word; handler  : Pointer);πProcedure setDefaultHandler(mask : Word);πProcedure enableLightPenEmulation;πProcedure disableLightPenEmulation;πProcedure defineSensetivity(x,y : Word);πProcedure setHideCursorBox(left,top,right,bottom : Word);πProcedure defineDoubleSpeedTreshHold(treshHold : Word);πProcedure disableTreshHold;πProcedure defaultTreshHold;πProcedure setMouseGraph;πProcedure resetMouseGraph;πProcedure waitForRelease(timeOut : Word);πProcedure swapEventHandler(mask : Word; handler : Pointer);π{ return old in lastMask and lastHandler }πFunction  getMouseSaveStateSize : Word;π{ get mouse from interrupted Program, and stop it ..}πProcedure interceptMouse;πProcedure restoreMouse;π{π**************************************************************************π*                                  MouseLib                              *     *π*                                                                        *     *π*               mouseLib     -      Release 2   and abo                  *π*                                                                        *π*  because of quirks in hercules Graphic mode that is not detectab       *     *π*   by the mouse driver we have to know when we initMouse if we wa       *     *π*   to check For Graphic mode or not, if we do we must perForm a         *π*   setMouseGraph beFore initGraph, to initGraph in Text mode we m       *     *π*   resetMouseGraph beFore.. , if these calling conventions are no       *     *π*   taken we might have problems in hercules cards!                      *π*                                                                        *     *π*  each call to hideMouseCursor must be balanced by a matching call      *     *π*   to showMouseCursor, 2 calls to hideMou.. and only 1 to showM..       *π*   will not show the mouse cursor on the screen!                        *π**************************************************************************π}πππImplementationππConst watchData : Array [0..31] of Word =π        ($E007,$C003,$8001,$0,$0,$0,$0,$0,$0,$0,$0,$0,$0,$8001,$C003,$E007,π         $0,$1FF8,$318C,$6186,$4012,$4022,$4042,$718C,$718C,$4062,$4032,π         $4002,$6186,$318C,$1FF8,$0);ππConst arrowData : Array [0..31] of Word =π        ($FFFF,$8FFF,$8FFF,$87FF,$83FF,$81FF,$80FF,$807F,$803F,$801F,$800F,π         $801F,$807F,$887F,$DC3F,$FC3F,π         $0,$0,$2000,$3000,$3800,$3C00,$3E00,$3F00,$3F80,$3FC0,π         $3FE0,$3E00,$3300,$2300,$0180,$0180);ππConst UpArrowCursor : Array [0..31] of Word =π         ($f9ff,$f0ff,$e07f,$e07f,$c03f,$c03f,$801f,$801f,π          $f,$f,$f0ff,$f0ff,$f0ff,$f0ff,$f0ff,$f0ff,π          $0,$600,$f00,$f00,$1f80,$1f80,$3fc0,$3fc0,π          $7fe0,$600, $600, $600, $600, $600, $600, $600);ππConst  LeftArrowCursor : Array [0..31] of Wordπ       = ($fe1f,$f01f,$0,   $0,   $0,   $f01f,$fe1f,$ffff,π          $ffff,$ffff,$ffff,$ffff,$ffff,$ffff,$ffff,$ffff,π          $0,   $c0,  $7c0, $7ffe,$7c0, $c0,  $0,   $0,π          $0,   $0,   $0,   $0,   $0,   $0,   $0,   $0);ππConst  CheckMarkCursor : Array [0..31] of Wordπ       = ($fff0,$ffe0,$ffc0,$ff81,$ff03,$607, $f,   $1f,π          $c03f,$f07f,$ffff,$ffff,$ffff,$ffff,$ffff,$ffff,π          $0,   $6,   $c,   $18,  $30,  $60,  $70c0,$1d80,π          $700, $0,   $0,   $0,   $0,   $0,   $0,   $0);ππConst  PointingHandCursor : Array [0..31] of Wordπ       = ($e1ff,$e1ff,$e1ff,$e1ff,$e1ff,$e000,$e000,$e000,π          $0,   $0,   $0,   $0,   $0,   $0,   $0,   $0,π          $1e00,$1200,$1200,$1200,$1200,$13ff,$1249,$1249,π          $f249,$9001,$9001,$9001,$8001,$8001,$8001,$ffff);ππConst  DiagonalcrossCursor : Array [0..31] of Wordπ       = ($7e0, $180, $0,   $c003,$f00f,$c003,$0,   $180,π          $7e0, $ffff,$ffff,$ffff,$ffff,$ffff,$ffff,$ffff,π          $0,   $700e,$1c38,$660, $3c0, $660, $1c38,$700e,π          $0,   $0,   $0,   $0,   $0,   $0,   $0,   $0);ππConst  RectangularCrossCursor : Array [0..31] of Wordπ       = ($fc3f,$fc3f,$fc3f,$0,$0,   $0,   $fc3f,$fc3f,π          $fc3f,$ffff,$ffff,$ffff,$ffff,$ffff,$ffff,$ffff,π          $0,   $180, $180, $180, $7ffe,$180, $180, $180,π          $0,   $0,   $0,   $0,   $0,   $0,   $0,   $0);ππConst  HourglassCursor : Array [0..31] of Wordπ       = ($0,   $0,   $0,   $0,   $8001,$c003,$e007,$f00f,π          $e007,$c003,$8001,$0,   $0,   $0,   $0,   $ffff,π          $0,   $7ffe,$6006,$300c,$1818,$c30, $660, $3c0,π          $660, $c30, $1998,$33cc,$67e6,$7ffe,$0,   $0);ππConst newWatchCursor : Array [0..31] of Wordπ       = ( $ffff, $c003, $8001, $0, $0, $0, $0, $0, $0,π           $0, $0, $0, $0, $8001, $c003, $ffff, $0, $0,π           $1ff8, $2004, $4992, $4022, $4042, $518a, $4782,π           $4002, $4992, $4002, $2004, $1ff8, $0, $0 );πππConstπ    mouseGraph : Boolean = False; {assume Text mode upon entry}ππTypeπ    box = Recordπ      left,top,right,bottom : Word;π  end; {Do not change field order !!!}ππVarπ  hideBox : box;π  reg : Registers;  {general Registers used}π  grMode,π  grDrv : Integer; {detect Graphic mode if any}π  grCode : Integer;     {return initGraph code in here}π  interceptX,π  interceptY : Word;π{π***************************************************************************π*                                  callMouse                              *    *π*                                                                         *    *π* used to call mouse interrupt With global data reg - used as parameters  *    *π***************************************************************************π}πProcedure callMouse;πbeginπ    intr(MOUSEinT,REG);πend; {callMouse}ππ(******************************************************************************π*                                  initMouse                                  *π* For some reason grCode is assigned a value of -11,($FFF5) in the second time*π*  we call initmouse after we allready are in Graphics mode, override.. was   *π*  born because of that situation.                                            *π******************************************************************************)ππProcedure initMouse;πVarπ    overRideDriver : Boolean; { True if we over-ridden stupid driver hercules b}πbeginπ    overRideDriver := False;π    if (mouseGraph and (mem[0:$449] = 7)) then begin { assume no mda - hercules}π          mem[0:$449] := 6;π      overRideDriver := True;π    end;π          {trick stupid mouse driver to know we are in Graphic mode}π        With reg doπ                beginπ            ax:=0; {detect genius mouse}π          bx:=0; {be sure what mode we get}π          callMouse;π          mouse_present := (ax <> 0); {not an iret..}π          if ((bx and 2) <> 0) thenπ                        mouse_buttons := twoButtonπ          else if ((bx and 3) <> 0)    thenπ                         mouse_buttons := threeButtonπ          elseπ                        mouse_buttons := another; {unknown to us}π        end; {with}π    if (overRideDriver) thenπ          mem[0:$449] := 7;π          {restore the stupid situation}π       eventX := 0;π       eventButtons := 0;π       eventY := 0;π       eventhappened := False;π       XMotions := 8;π       YMotions := 16;π       mouseCursorLevel := 0; { not visiable, one show to appear }πend; {initMouse}ππ(******************************************************************************ππ*                               showMouseCursor                               *ππ******************************************************************************)ππProcedure showMouseCursor;ππbeginπ        reg.ax:=1; {enable cursor display}π        callMouse;π        inc(mouseCursorLevel);πend; {showMouseCursor}ππ(******************************************************************************ππ*                               hideMouseCursor                               *ππ******************************************************************************)ππProcedure hideMouseCursor;ππbeginπ        reg.ax:=2; {disable cursor display}π        callMouse;π        dec(mouseCursorLevel);πend; {hideMouseCursor}ππ(******************************************************************************ππ*                                  getMouseX                                  *ππ******************************************************************************)ππFunction getMouseX : Word;πππbeginπ        reg.ax := 3;π        callMouse;π        getMouseX := reg.cx;πend; {getMouseX}ππ(******************************************************************************ππ*                                  getMouseY                                  *ππ******************************************************************************)ππFunction getMouseY : Word;ππbeginπ        reg.ax := 3;π        callMouse;π        getMouseY := reg.dx;πend; {getMouseX}ππ(******************************************************************************ππ*                                  getButton                                  *ππ******************************************************************************)ππFunction getButton(Button : Byte) : buttonState;ππbeginπ        reg.ax := 3;π        callMouse;π        if ((reg.bx and Button) <> 0) thenπ                getButton := buttonDownπ                {bit 0 = left, 1 = right, 2 = middle}π        else getButton := buttonUp;πend; {getButton}ππ(******************************************************************************ππ*                                buttonPressed                                *ππ******************************************************************************)ππFunction buttonPressed : Boolean;ππbeginπ        reg.ax := 3;π        callMouse;π         if ((reg.bx and 7) <> 0) thenπ                buttonPressed := Trueπ        else buttonPressed := False;πend; {buttonPressed}ππ(******************************************************************************ππ*                               setMouseCursor                                *ππ******************************************************************************)ππProcedure setMouseCursor(x,y : Word);ππbeginπ        With reg do beginπ                ax := 4;π                cx := x;π                dx := y; {prepare parameters}π                callMouse;π        end; {with}πend; {setMouseCursor}ππ(******************************************************************************ππ*                                 lastXPress                                  *ππ******************************************************************************)ππFunction lastXPress(Button : Byte) : Word;ππbeginπ        reg.ax := 5;π        reg.bx := Button;π        callMouse;π        lastXPress := reg.cx;πend; {lastXpress}ππ(******************************************************************************ππ*                                 lastYPress                                  *ππ******************************************************************************)ππFunction lastYPress(Button : Byte) : Word;ππbeginπ        reg.ax := 5;π        reg.bx := Button;π        callMouse;π        lastYPress := reg.dx;πend; {lastYpress}ππ(******************************************************************************ππ*                                buttonPresses                                *ππ******************************************************************************)ππFunction buttonPresses(Button : Byte) : Word; {from last check}ππbeginπ        reg.ax := 5;π        reg.bx := Button;π        callMouse;π        buttonPresses := reg.bx;πend; {buttonPresses}πππ(******************************************************************************ππ*                                lastXRelease                                 *ππ******************************************************************************)ππFunction lastXRelease(Button : Byte) : Word;ππbeginπ        reg.ax := 6;π        reg.bx := Button;π        callMouse;π        lastXRelease := reg.cx;πend; {lastXRelease}ππ(******************************************************************************ππ*                                lastYRelease                                 *ππ******************************************************************************)ππFunction lastYRelease(Button : Byte) : Word;ππbeginπ        reg.ax := 6;π        reg.bx := Button;π        callMouse;π        lastYRelease := reg.dx;πend; {lastYRelease}ππ(******************************************************************************ππ*                               buttonReleases                                *ππ******************************************************************************)ππFunction buttonReleases(Button : Byte) : Word; {from last check}ππbeginπ        reg.ax := 6;π        reg.bx := Button;π        callMouse;π        buttonReleases := reg.bx;πend; {buttonReleases}ππ(******************************************************************************ππ*                                    swap                                     *ππ******************************************************************************)ππProcedure swap(Var a,b : Word);ππVar c : Word;ππbeginπ        c := a;π        a := b;π        b := c; {swap a and b}πend; {swap}ππ(******************************************************************************ππ*                                  mouseBox                                   *ππ******************************************************************************)ππProcedure mouseBox(left,top,right,bottom : Word);ππbeginπ        if (left > right) then swap(left,right);π        if (top > bottom) then swap(top,bottom); {make sure they are ordered}π        reg.ax := 7;π        reg.cx := left;π        reg.dx := right;π        callMouse; {set x range}π        reg.ax := 8;π        reg.cx := top;π        reg.dx := bottom;π        callMouse; {set y range}πend; {mouseBox}ππ(******************************************************************************ππ*                             GraphicMouseCursor                              *ππ******************************************************************************)ππProcedure GraphicMouseCursor(xHotPoint,yHotPoint : Byte; dataofs : Pointer);ππ{define 16*16 cursor mask and screen mask, pointed by data,π        dataofs is Pointer to data of the masks.}ππbeginπ        reg.ax := 9;π        reg.bx := xHotPoint;π        reg.cx := yHotPoint;π        reg.dx := ofs(dataofs^);        {DS:DX point to masks}π        reg.es := seg(dataofs^);π        callMouse;π        lastCursor.xH := xHotPoint;π        lastCursor.yH := yHotPoint;π        lastCursor.data := dataofs;π        {save it in lastCursor, if someone needs to change cursor temporary}πend; {GraphicMouseCursor}ππ(******************************************************************************ππ*                             HardwareTextCursor                              *ππ******************************************************************************)ππProcedure HardwareTextCursor(fromLine,toLine : Byte);ππ{set Text cursor to Text, using the scan lines from..to,ππ(Continued to next message)π--- FreeMail 1.07bπ * origin: Meredith Place BBS * Tucson, AZ * 602-579-0869 * (1:300/15)π<<<>>>πππDate: 03-02-93 (20:07)              Number: 14561 of 14567 (Echo)π  to: ROBERT BAKER                  Refer#: NONEπFrom: STEVE CONNET                    Read: NOπSubj: MOUSE               6/10      Status: PUBLIC MESSAGEπConf: F-PASCAL (1221)            Read Type: GENERAL (+)ππ(Continued from previous message)ππ        same as intr 10 cursor set in bios :π        color scan lines 0..7, monochrome 0..13 }ππbeginπ{        reg.ah:=$10;π        reg.ch:=fromLine;π        reg.cl:=toLine;π}π        reg.ax := 10;π        reg.bx := 1; {hardware Text}π        reg.cx := fromLine;π        reg.dx := toLine;π        callMouse;πend; {hardwareTextCursor}ππ(******************************************************************************ππ*                             softwareTextCursor                              *ππ******************************************************************************)ππProcedure softwareTextCursor(screenMask,cursorMask : Word);ππ{ when in this mode the cursor will be achived by anding the screen Wordπ        With the screen mask (Attr,Char in high,low order) andπ        xoring the cursor mask, ussually used by putting the screen attrπ        we want preserved in screen mask (and 0 into screen mask Characterπ        Byte), and Character + attributes we want to set into cursor mask}ππbeginπ        reg.ax := 10;π        reg.bx := 0;    {software cursor}π        reg.cx := screenMask;π        reg.dx := cursorMask;π        callMouse;πend; {softwareMouseCursor}ππ(******************************************************************************ππ*                               recentXmovement                               *ππ******************************************************************************)ππFunction recentXmovement : direction;ππ{from recent call to which direction did we move ?}ππVar d : Integer;ππbeginπ        reg.ax := 11;π        callMouse;π        d := reg.cx;π        if (d > 0)π                then recentXmovement := moveRightπ        else if (d < 0)π                then recentXmovement := moveLeftπ        else recentXmovement := noMove;πend; {recentXmovement}ππ(******************************************************************************ππ*                               recentYmovement                               *ππ******************************************************************************)ππFunction recentYmovement : direction;ππ{from recent call to which direction did we move ?}ππVarπ   d : Integer;πbeginπ        reg.ax := 11;π        callMouse;π        d := reg.dx;π        if (d > 0)π                then recentYmovement := moveDownπ        else if (d < 0)π                then recentYmovement := moveUpπ        else recentYmovement := noMove;πend; {recentYmovement}ππ(******************************************************************************ππ*                               setWatchCursor                                *ππ******************************************************************************)ππProcedure setWatchCursor;πbeginπ        GraphicMouseCursor(0,0,@watchData);πend; {setWatchCursor}ππ(******************************************************************************ππ*                              setNewWatchCursor                              *ππ******************************************************************************)ππProcedure setNewWatchCursor;πbeginπ   GraphicMouseCursor(0, 0, @newWatchCursor);πend; {setNewWatchCursor}ππ(******************************************************************************ππ*                              setUpArrowCursor                               *ππ******************************************************************************)ππProcedure setUpArrowCursor;ππbeginπ        GraphicMouseCursor(5, 0, @upArrowCursor);πend; {setUpArrowCursor}ππ(******************************************************************************ππ*                             setLeftArrowCursor                              *ππ******************************************************************************)ππProcedure setLeftArrowCursor;πbeginπ        GraphicMouseCursor(0, 3, @leftArrowCursor);πend; {setLeftArrowCursor}ππ(******************************************************************************ππ*                             setCheckMarkCursor                              *ππ******************************************************************************)ππProcedure setCheckMarkCursor;πbeginπ        GraphicMouseCursor(6, 7, @checkMarkCursor);πend; {setCheckMarkCursor}ππ(******************************************************************************ππ*                            setPointingHandCursor                            *ππ******************************************************************************)ππProcedure setPointingHandCursor;πbeginπ        GraphicMouseCursor(5, 0, @pointingHandCursor);πend; {setPointingHandCursor}ππ(******************************************************************************ππ*                           setDiagonalCrossCursor                            *ππ******************************************************************************)ππProcedure setDiagonalCrossCursor;πbeginπ        GraphicMouseCursor(7, 4, @diagonalCrossCursor);πend; {setDiagonalCrossCursor}ππ(******************************************************************************ππ*                          setRectangularCrossCursor                          *ππ******************************************************************************)ππProcedure setRectangularCrossCursor;πbeginπ        GraphicMouseCursor(7, 4, @rectangularCrossCursor);πend; {setRectangularCrossCursor}ππ(******************************************************************************ππ*                             setHourGlassCursor                              *ππ******************************************************************************)ππProcedure setHourGlassCursor;πbeginπ        GraphicMouseCursor(7, 7, @hourGlassCursor);πend; {setHourGlassCursor}ππ(******************************************************************************ππ*                               setArrowCursor                                *ππ******************************************************************************)ππProcedure setArrowCursor;πbeginπ        GraphicMouseCursor(1,1,@arrowData);πend; {setArrowCursor}ππ(******************************************************************************ππ*                               setEventHandler                               *ππ******************************************************************************)ππProcedure setEventHandler(mask : Word; handler  : Pointer);ππ{handler must be a Far interrupt routine }ππbeginπ        reg.ax := 12; {set event handler Function in mouse driver}π        reg.cx := mask;π        reg.es := seg(handler^);π        reg.dx := ofs(handler^);π        callMouse;π        lastMask := mask;π        lastHandler := handler;πend; {set event Handler}ππ(******************************************************************************ππ*                               defaultHandler                                *ππ******************************************************************************)ππ{$F+} Procedure defaultHandler; Assembler; {$F-}πAsmπ   push ds; { save TP mouse driver }π   mov ax, SEG @data;π   mov ds, ax; { ds = TP:ds, not the driver's ds }π   mov eventX, cx; { where in the x region did it occur }π   mov eventY, dx;π   mov eventButtons, bx;π   mov eventHappened, 1; { eventHapppened := True }π   pop ds; { restore driver's ds }π   ret;πend;ππ{   this is the default event handler , it simulates :ππ      beginπ               eventX := cx;π               eventY := dx;π               eventButtons := bx;π               eventhappened := True;π      end;ππ}ππ(******************************************************************************ππ*                                GetLastEvent                                 *ππ******************************************************************************)ππFunction GetLastEvent(Var x,y : Word;π        Var left_button,right_button,middle_button : buttonState) : Boolean;ππbeginπ        getLastEvent := eventhappened; {indicate if any event happened}π        eventhappened := False; {clear to next read/event}π        x := eventX;π        y := eventY;π        if ((eventButtons and LEFTBUTtoN) <> 0) thenπ                left_button := buttonDownπ        else left_button := buttonUp;π        if ((eventButtons and RIGHTBUTtoN) <> 0) thenπ                right_button := buttonDownπ        else right_button := buttonUp;π        if ((eventButtons and MIDDLEBUTtoN) <> 0) thenπ                middle_button := buttonDownπ        else middle_button := buttonUp;πend; {getLastEvent}ππ(******************************************************************************ππ*                              setDefaultHandler                              *ππ******************************************************************************)ππProcedure setDefaultHandler;ππ{get only event mask, and set event handler to defaultHandler}ππbeginπ        setEventHandler(mask,@defaultHandler);πend; {setDefaultHandler}ππ(******************************************************************************ππ*                           enableLightPenEmulation                           *ππ******************************************************************************)ππProcedure enableLightPenEmulation;ππbeginπ        reg.ax := 13;π        callMouse;πend; {enableLightPenEmulation}ππ(******************************************************************************ππ*                          disableLightPenEmulation                           *ππ******************************************************************************)ππProcedure disableLightPenEmulation;ππbeginπ        reg.ax := 14;π        callMouse;πend;  {disableLightPenEmulation}ππ(******************************************************************************ππ*                              defineSensetivity                              *ππ******************************************************************************)ππProcedure defineSensetivity(x,y : Word);ππbeginπ        reg.ax := 15;π        reg.cx := x; {# of mouse motions to horizontal 8 pixels}π        reg.dx := y; {# of mouse motions to vertical 8 pixels}π        callMouse;π        XMotions := x;π        YMotions := y; {update global Unit Variables}πend; {defineSensetivity}ππ(******************************************************************************ππ*                              setHideCursorBox                               *ππ******************************************************************************)ππProcedure setHideCursorBox(left,top,right,bottom : Word);ππbeginπ        reg.ax := 16;π        reg.es := seg(HideBox);π        reg.dx := ofs(HideBox);π        HideBox.left := left;π        HideBox.right := right;π        HideBox.top := top;π        HideBox.bottom := bottom;π        callMouse;πend; {setHideCursorBox}ππ(******************************************************************************ππ*                         defineDoubleSpeedTreshHold                          *ππ******************************************************************************)ππProcedure defineDoubleSpeedTreshHold(treshHold : Word);ππbeginπ        reg.ax := 17;π        reg.dx := treshHold;π        callMouse;πend; {defineDoubleSpeedTreshHold - from what speed to Double mouse movement}ππ(******************************************************************************ππ*                              disableTreshHold                               *ππ******************************************************************************)ππProcedure disableTreshHold;ππbeginπ        defineDoubleSpeedTreshHold($7FFF);πend; {disableTreshHold}ππ(******************************************************************************ππ*                              defaultTreshHold                               *ππ******************************************************************************)ππProcedure defaultTreshHold;ππbeginπ        defineDoubleSpeedTreshHold(64);πend; {defaultTreshHold}ππ(******************************************************************************ππ*                                setMouseGraph                                *ππ******************************************************************************)ππProcedure setMouseGraph;ππbeginπ        mouseGraph := True;πend; {setMouseGraph}ππ(******************************************************************************ππ*                               resetMouseGraph                               *ππ******************************************************************************)ππProcedure resetMouseGraph;ππbeginπ        mouseGraph := False;πend; {resetMouseGraph}πππ(******************************************************************************ππ*                               waitForRelease                                *ππ* Wait Until button is release, or timeOut 1/100 seconds pass. (might miss a  *ππ* tenth (1/10) of a second.ππ******************************************************************************)ππProcedure waitForRelease;πVarπ    sHour, sMinute, sSecond, sSec100 : Word;    { Time at start }π    cHour, cMinute, cSecond, cSec100 : Word;    { Current time  }π    stopSec                          : longInt;π    currentSec                    : longInt;π    Delta                            : longInt;πbeginπ    getTime(sHour, sMinute, sSecond, sSec100);π    stopSec := (sHour*36000 + sMinute*600 + sSecond*10 + sSec100 + timeOut) modππ                    (24*360000);π    Repeatπ           getTime(cHour, cMinute, cSecond, cSec100);π           currentSec := (cHour*36000 + cMinute*600 + cSecond*10 + cSec100);π           Delta := currentSec - stopSec;π    Until (not ButtonPressed) or (Delta >=0) and (Delta < 36000);πend; {waitForRelease}ππ(******************************************************************************ππ*                              swapEventHandler                               *ππ* handler is a Far routine.                                                   *ππ******************************************************************************)ππProcedure swapEventHandler;πbeginπ   reg.ax := $14;π   reg.cx := mask;π        reg.es := seg(handler^);π        reg.dx := ofs(handler^);π        callMouse;π   lastMask := reg.cx;π   lastHandler := ptr(reg.es,reg.dx);πend; {swapEventHandler}ππ(******************************************************************************ππ*                            getMouseSaveStateSize                            *ππ******************************************************************************)ππFunction getMouseSaveStateSize;πbeginπ   reg.ax := $15;π   callMouse;π   getMouseSaveStateSize := reg.bx;πend; {getMouseSaveStateSize}πππ(******************************************************************************ππ*                               interceptMouse                                *ππ******************************************************************************)ππProcedure interceptMouse;πbeginπ   With reg do beginπ      ax := 3;π      callMouse; { get place .. }π      interceptX := cx;π      interceptY := dx;π      ax := 31;π      callMouse;π   end; { disable mouse driver .. }πend; {interceptMouse}ππ(******************************************************************************ππ*                                restoreMouse                                 *ππ******************************************************************************)ππProcedure restoreMouse;πbeginπ   With reg do beginπ      ax := 32; { restore mouse driver .. }π      callMouse;π      ax := 4;π      cx := interceptX;π      dx := interceptY;π      callMouse;π   end; { With .. }πend; {restoreMouse}ππVarπ    OldExitProc : Pointer;ππ(******************************************************************************ππ*                                 MyExitProc                                  *ππ******************************************************************************)ππ{$f+}Procedure MyExitProc;πbeginπ    ExitProc := OldExitProc;π    resetMouseGraph;π    initMouse;πend; { myExitProc }ππ{ if this Unit is used With a Graphic Unit that is loaded and executed afterπ     this Unit in the Uses clause, the mouse initialization will not beπ     correct, be sure to call initMouse in your Program start to workπ     properly }ππbegin   {Unit initialization}π   eventX := 0;π   eventY := 0;π   eventHappened := False; { initialize ... }π        initMouse; {detect in global Variables}π        setArrowCursor; {start like that in Graphic mode}π        OldExitProc := ExitProc;π        ExitProc    := @MyExitProc;πend. {mouseLib}πππππππππThis is a demonstration of the previous Unit Robert.πππ(******************************************************************************ππ*                                  mouseTest                                  *ππ* This is a simple test Program that shows if the mouse is Functions, andππ* demonstrates basic mouse Programming using the mouseLib Unit.ππ******************************************************************************)ππProgram mouseTest;ππUses mouse,Crt,Graph;ππVarπ   grdriver,π   grmode,π   ErrCode : Integer;ππProcedure Err(Msg: String);πbeginπ  Writeln(Msg);πend;ππbeginπ     clrScr;π     if not (mouse_present) then beginπ     { mouse_present was set by the mouseLib initialization code .. }π          Write('mouse not installed');π          Exit;π     end;π     Case mouse_buttons ofπ          twoButton : WriteLn('MicroSoft mouse Mode');π          threeButton : WriteLn('PC mouse Mode');π          else WriteLn('UnRecognized mouse mode');π     end; {Case}π     Writeln('MouseLib demo Program, (c) 1992, Ron Loewy.');π     Writeln;π     Writeln('Move Cursor, Press Right & Left buttons together to continue');π     Writeln('             Press any mouse button by itself to recognize');π     Window(10, 7, 70, 20);π     hardwareTextCursor(1,13); { "normal" Text cursor }π     showMouseCursor; { display the cursor }π     Repeatπ           if getButton(leftButton) = buttonDown thenπ              WriteLn('Left Button Pressed');π           if getButton(rightButton) = buttonDown thenπ              WriteLn('right Button Pressed');π           if getButton(middleButton) = buttonDown thenπ              WriteLn('Middle Button Pressed');π     Until (getButton(leftButton) = buttonDown) andπ           (getButton(RightButton) = buttonDown);π     hideMouseCursor; { we hide the cursor }π     grDriver := detect;π     initGraph(grDriver, grMode, 'D:\TP\BGI');π     ErrCode := GraphResult;π     if ErrCode <> grOK then Err('ERRor! not initializing:'+GraphErrorMsg(ErrCoππ     setMouseGraph; { fix quircks in Herc. Graphic card }π     initMouse; { let the mouse sense it is in Graphic mode }π     outTextXY(10, 10, 'MouseLib demo Program, (c) 1992, Ron Loewy.');π     outTextXY(10, 30, 'Press the Right Button to end');π     showMouseCursor; { draw the Graphic default arrow cursor }π     Repeat Until getButton(rightButton) = buttonDown;π     hideMouseCursor;π     closeGraph;πend.π                                                                              2      05-28-9313:52ALL                      SWAG SUPPORT TEAM        MOUSPIC1.PAS             IMPORT              23          {π>    I'm interested in how to change the default mouse cursor toπ> another user defined shape.  if you know how to do that, can youπ> please post the source For it?  Thanks in advance.π}πππUsesπ  Dos, Graph;ππVarπ   Regs : Registers;ππTypeπ   CursorType = Array[0..31] of Word;   { to store the cursor shape }πππ{ define a cursor shape }πConst HourGlass : CursorType =ππ  { this specific Constant, when used in the Procedure to change the cursorπ    shape will change it to an hourglass shaped cursor.  of course you canπ    define your own cursor shape to suit your needs.π    the comments beside the hex numbers are what it will look like (binary),π    they help TREMendOUSLY in designing a cursor shape. }πππ  { Screen mask : the 0's will show up as the background colour, the 1'sπ    will show whatever is on the screen at that location }ππ   ($0001,  { 0000000000000001 }π    $0001,  { 0000000000000001 }π    $8003,  { 1000000000000011 }π    $C7C7,  { 1100011111000111 }π    $E38F,  { 1110001110001111 }π    $F11F,  { 1111000100011111 }π    $F83F,  { 1111100000111111 }π    $FC7F,  { 1111110001111111 }π    $F83F,  { 1111100000111111 }π    $F11F,  { 1111000100011111 }π    $E38F,  { 1110001110001111 }π    $C7C7,  { 1100011111000111 }π    $8003,  { 1000000000000011 }π    $0001,  { 0000000000000001 }π    $0001,  { 0000000000000001 }π    $0000,  { 0000000000000000 }ππ  { Cursor mask : the 1's will show up as white (or whatever color you haveπ    reassigned it to if you have done a SetPalette or SetRGBPalette) }ππ    $0000,  { 0000000000000000 }π    $7FFC,  { 0111111111111100 }π    $2008,  { 0010000000001000 }π    $1010,  { 0001000000010000 }π    $0820,  { 0000100000100000 }π    $0440,  { 0000010001000000 }π    $0280,  { 0000001010000000 }π    $0100,  { 0000000100000000 }π    $0280,  { 0000001010000000 }π    $0440,  { 0000010001000000 }π    $0820,  { 0000100000100000 }π    $1010,  { 0001000000010000 }π    $2008,  { 0010000000001000 }π    $7FFC,  { 0111111111111100 }π    $0000,  { 0000000000000000 }π    $0000); { 0000000000000000 }ππProcedure SetMouseCursor(HotX, HotY: Integer; Var Pattern : CursorType);πbeginπ  Regs.AX := 9;    { Function 9 }π  Regs.BX := HotX; { X-ordinate of hot spot }π  Regs.CX := HotY; { Y-ordinate of hot spot }π  { the hot spots are the co-ordinates that will show up as being whereπ    the mouse is when reading the co-ordinates of the mouse }π  Regs.DX := ofs(Pattern);π  Regs.ES := Seg(Pattern);π  Intr($33, Regs);πend;ππbeginπ   { [...initialize the Graphics screen etc...] }ππ   SetMouseCursor(7, 7, HourGlass);π   { this will set the mouse cursor to an hourglass shape With the hot spotπ     right in the centre at position 7,7 from the top left of the shape }ππ   { [...continue Program...] }πend.π                                                                 3      05-28-9313:52ALL                      SWAG SUPPORT TEAM        MOUSPIC2.PAS             IMPORT              11          {π>Hey Programmers,π>    I'm trying to change the way my mouse cursor looks in one of myπ>Programs from the standard block to an arrow.  I looked up the inFormationπ>in my interrupt list and found that I need to use Interrupt 33h (Bigπ>surprise) With AX = 0009h.  I'm ok up to this point, but the inFormationπ>lost me when is says that ES:DX->bitmap With 16 Words screen mask and 16π>Words cursor mask.  Now I know what it means and have already defined theπ>code For my curse, but how do I assign ES:DX to its value? (Source exampleπ>below).  Any help would be great and please E-MAIL it to me.  Thanksπ}ππConstπ   ArrowCursor: Array [0..31] of Word = (π        $3fff,$1fff,$fff,$7ff,$3ff,$1ff,$ff,$7f,π       $3f,$1f,$f,$7,$1847,$387f,$fc3f,$fe7f,π       $0,$4000,$6000,$7000,$7800,$7c00,$7e00,$7f00,π       $7f80,$7fc0,$7fe0,$6730,$4300,$300,$180,$0);π   HotSpotX : Word = 1;π   HotSpotY : Word = 0;πππProcedure ArrowMouse;πVar regs : Registers;πbeginπ   Regs.AX := $000A;π   Regs.BX := HotSpotX;π   Regs.CX := HotSpotY;ππ   { ES:DX -> bitmap  16 Words screen mask  16 Words cusor mask }π   Regs.ES := Seg(ArrowCursor); { Answer :) }π   Regs.DX := ofs(ArrorCursor); { Answer :) }ππ   intr($33,Regs);πend;ππ                                                                                      4      05-28-9313:52ALL                      SWAG SUPPORT TEAM        RODENT.PAS               IMPORT              51          Unit Rodent;πInterfaceπUses Dos;ππconst MDD = $33;   { mouse interupt }π                   { Interupt driven        Polled       = AX  }π      bit_0 = $01; { mouse movement         left button down   }π      bit_1 = $02; { left button pressed    right button down  }π      bit_2 = $04; { left button released   center button down }π      bit_3 = $08; { right button pressed }π      bit_4 = $10; { right button released }π      bit_5 = $20; { center pressed }π      bit_6 = $40; { center released }π      bit_7 = $80;ππtypeπ  resetRec = recordπ    exists   : Boolean;π    nButtons : Integer;π  end;π  LocRec = recordπ    buttonStatus,π    opCount,π    column,π    row       : Integer;π  end;π  moveRec = recordπ    hCount,π    vCount    : Integer;π  end;π{$F+}π  eventRec = recordπ               flag, button, col, row: Word;π             end;π{$F-}ππvar mReg     : Registers;π    theMouse : resetRec;     { Does mouse exist }π    mrecord  : locRec;       { polled record    }π    mEvent   : eventRec;     { interupt record  }ππprocedure mFixXY (x1,y1,x2,y2:integer);πfunction mouseX (n:integer) : integer;πfunction mouseY (n:integer) : integer;πprocedure mReset (VAR Mouse: resetRec);                                {  0 }πprocedure mShow;                                                       {  1 }πprocedure mHide;                                                       {  2 }πprocedure mPos (VAR Mouse: LocRec);                                    {  3 }πprocedure mMoveto (col, row: Integer);                                 {  4 }πprocedure mPressed (button: Integer; VAR Mouse: LocRec);               {  5 }πprocedure mReleased (button: Integer; VAR Mouse: LocRec);              {  6 }πprocedure mColRange (min, max : Integer);                              {  7 }πprocedure mRowRange (min, max : Integer);                              {  8 }πprocedure mGraphCursor (hHot, vHot: Integer; maskSeg, maskOfs: Word);  {  9 }πprocedure mTextCursor (ctype, p1, p2: Word);                           { 10 }πprocedure mMotion (VAR moved: moveRec);                                { 11 }πprocedure mInstTask (mask: Word);                                      { 12 }πprocedure mLpenOn;                                                     { 13 }πprocedure mLpenOff;                                                    { 14 }πprocedure mRatio (horiz, vert: Integer);                               { 15 }ππimplementationπvarπ  maxcol   : word absolute $0040:$004A;   { x }ππprocedure EventHandler(Flags,CS,AX,BX,CX,DX,SI,DI,DS,ES,BP: Word);πinterrupt;πbeginπ  mEvent.flag   := AX;π  mEvent.button := BX;π  mEvent.col    := CX;π  mEvent.row    := DX;π  inLine($8B/$E5/$5D/$07/$1F/$5F/$5E/$5A/$59/$5B/$58/$CB);πend;ππfunction Lower (n1, n2: Integer): Integer;π  beginπ    if n1 < n2 then Lower := n1 else Lower := n2;π  end;ππfunction Upper (n1, n2: Integer): Integer;π  beginπ    if n1 > n2 then Upper := n1 else Upper := n2;π  end;ππprocedure mFixXY;π  var i : integer;π  beginπ    if maxcol = 80π    then i := 3π    else i := 4;π    mColRange(pred(x1) shl i,pred(x2) shl i);π    mRowRange(pred(y1) shl 3,pred(y2) shl 3);π  end;ππfunction mouseX;π  var i : integer;π  beginπ    if maxcol = 80π    then i := 3π    else i := 4;π    mouseX := succ(n shr i);π  end;ππfunction mouseY;π  beginπ    mouseY := succ(n shr 3);π  end;ππprocedure mReset (VAR Mouse: resetRec);π  beginπ    mreg.ax := 0;π    intr(MDD, mreg);π    Mouse.exists := boolean(mreg.ax <> 0);π    Mouse.nButtons := mreg.bx;π  end;ππprocedure mShow;π  beginπ    inline($B8/$01/$00/$CD/MDD);π{    mreg.ax := 1;    }π{    intr(MDD, mreg); }π  end;ππprocedure mHide;π  beginπ    inline($B8/$02/$00/$CD/MDD);π{    mreg.ax := 2;    }π{    intr(MDD, mreg); }π  end;ππprocedure mPos (VAR Mouse: LocRec);π  beginπ    mreg.ax := 3;π    intr(MDD, mreg);π    Mouse.buttonStatus := mreg.bx;π    Mouse.column := mreg.cx;π    Mouse.row := mreg.dx;π  end;ππprocedure mMoveto (col, row: Integer);π  var i : word;π  beginπ    if maxcol = 80π    then i := 3π    else i := 4;π    mreg.ax := 4;π    mreg.cx := col shl i;π    mreg.dx := row shl i;;π    intr(MDD, mreg);π  end;ππprocedure mPressed (button: Integer; VAR Mouse: LocRec);π  beginπ    mreg.ax := 5;π    mreg.bx := button;π    intr(MDD, mreg);π    Mouse.buttonStatus := mreg.ax;π    Mouse.opCount := mreg.bx;π    Mouse.column := mreg.cx;π    Mouse.row := mreg.dx;π  end;ππprocedure mReleased (button: Integer; VAR Mouse: LocRec);π  beginπ    mreg.ax := 6;π    mreg.bx := button;π    intr(MDD, mreg);π    Mouse.buttonStatus := mreg.ax;π    Mouse.opCount := mreg.bx;π    Mouse.column := mreg.cx;π    Mouse.row := mreg.dx;π  end;ππprocedure mColRange (min, max : Integer);π  beginπ    mreg.ax := 7;π    mreg.cx := Lower(min, max);π    mreg.dx := Upper(min, max);π    intr(MDD, mreg);π  end;ππprocedure mRowRange (min, max : Integer);π  beginπ    mreg.ax := 8;π    mreg.cx := Lower (min, max);π    mreg.dx := Upper (min, max);π    intr(MDD, mreg);π  end;ππprocedure mGraphCursor (hHot, vHot: Integer; maskSeg, maskOfs: Word);π  beginπ    mreg.ax := 9;π    mreg.bx := hHot;π    mreg.cx := vHot;π    mreg.dx := maskOfs;π    mreg.es := maskSeg;π    intr(MDD, mreg);π  end;ππprocedure mTextCursor (ctype, p1, p2: Word);π  beginπ    mreg.ax := 10;π    mreg.bx := ctype;       { 0=software, 1=hardware          }π    mreg.cx := p1;          { 0=and mask else start line      }π    mreg.dx := p2;          { 0=xor mask else Cursor end line }π    intr(MDD, mreg);π  end;ππ{ Returns mouse displacement in mickeys since last call }πprocedure mMotion (VAR moved: moveRec);π  beginπ    mreg.ax := 11;π    intr(MDD, mreg);π    moved.hCount := mreg.cx;π    moved.vCount := mreg.dx;π  end;ππprocedure mInstTask;π  beginπ    mreg.ax := 12;π    mreg.cx := mask;         { see bit constants above }π    mreg.dx := Ofs(EventHandler);π    mreg.es := Seg(EventHandler);π    intr(MDD, mreg);π  end;ππprocedure mLpenOn;π  beginπ    mreg.ax := 13;π    intr(MDD, mreg);π  end;ππprocedure mLpenOff;π  beginπ    mreg.ax := 14;π    intr(MDD, mreg);π  end;ππprocedure mRatio (horiz, vert: Integer);π  beginπ    mreg.ax := 15;π    mreg.cx := horiz;π    mreg.dx := vert;π    intr(MDD, mreg);π  end;ππ{ Sample base line program...π  mReset(theMouse);π  if theMouse.existsπ  then minstTask(15);      (* for 80x25 *)π  mFixXY(1,1,succ(lo(windmax)),succ(hi(windmax)));π  mEvent.Flag := 0;π<< do the program >>π  mReset(theMouse);π}πEND.ππ